package j2024.j202408;

public class j0811 {
    public String countAndSay(int n) {
        String ret = "1";
        for (int i = 1; i < n; i++) {
            StringBuilder sb = new StringBuilder();
            int len = ret.length();
            for (int left = 0,right = 0; right < len; ) {

                while(right<len && ret.charAt(left) == ret.charAt(right)){
                    right++;
                }
                sb.append(Integer.toString(right-left));
                sb.append(ret.charAt(left));
                left = right;
            }
            ret = sb.toString();
        }
        return ret;
    }

}
